package com.study.wilbur.filter;

import com.study.wilbur.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author : wilbur.yuan
 * @date : 2019-02-22
 */
public class PermissionFilter implements Filter {

    @Autowired
    private PermissionService permissionService;

    @Override
    public void init(FilterConfig filterConfig) {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {

        permissionService.doSomething();
        filterChain.doFilter(servletRequest, servletResponse);

    }
}
